package com.sdb.medicalrecord.service.impl;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

import com.sdb.clinic.service.ITdRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sdb.medicalrecord.mapper.TdMedicalrecordMapper;
import com.sdb.medicalrecord.domain.TdMedicalrecord;
import com.sdb.medicalrecord.service.ITdMedicalrecordService;

/**
 * 病历Service业务层处理
 * 
 * @author yyh
 * @date 2025-01-24
 */
@Service
public class TdMedicalrecordServiceImpl implements ITdMedicalrecordService 
{
    @Autowired
    private TdMedicalrecordMapper tdMedicalrecordMapper;

    @Autowired
    private ITdRegisterService tdRegisterService;

    /**
     * 查询病历
     * 
     * @param clinicId 病历主键
     * @return 病历
     */
    @Override
    public TdMedicalrecord selectTdMedicalrecordByClinicId(String clinicId)
    {
        return tdMedicalrecordMapper.selectTdMedicalrecordByClinicId(clinicId);
    }

    @Override
    public int insertClinicId(String clinicId) {
        return tdMedicalrecordMapper.insertClinicId(clinicId);
    }

    /**
     * 查询病历列表
     * 
     * @param tdMedicalrecord 病历
     * @return 病历
     */
    @Override
    public List<TdMedicalrecord> selectTdMedicalrecordList(TdMedicalrecord tdMedicalrecord)
    {
        return tdMedicalrecordMapper.selectTdMedicalrecordList(tdMedicalrecord);
    }

    /**
     * 新增病历
     * 
     * @param tdMedicalrecord 病历
     * @return 结果
     */
    @Override
    public int insertTdMedicalrecord(TdMedicalrecord tdMedicalrecord)
    {
        return tdMedicalrecordMapper.insertTdMedicalrecord(tdMedicalrecord);
    }

    /**
     * 修改病历
     * 
     * @param tdMedicalrecord 病历
     * @return 结果
     */
    @Override
    public int updateTdMedicalrecord(TdMedicalrecord tdMedicalrecord)
    {
        // 设置病历的修改时间为当前时间
        tdMedicalrecord.setCreatedate(new Date());
        tdRegisterService.updateStatus(tdMedicalrecord.getClinicId());
        return tdMedicalrecordMapper.updateTdMedicalrecord(tdMedicalrecord);
    }

    /**
     * 批量删除病历
     * 
     * @param clinicIds 需要删除的病历主键
     * @return 结果
     */
    @Override
    public int deleteTdMedicalrecordByClinicIds(String[] clinicIds)
    {
        return tdMedicalrecordMapper.deleteTdMedicalrecordByClinicIds(clinicIds);
    }

    /**
     * 删除病历信息
     * 
     * @param clinicId 病历主键
     * @return 结果
     */
    @Override
    public int deleteTdMedicalrecordByClinicId(String clinicId)
    {
        return tdMedicalrecordMapper.deleteTdMedicalrecordByClinicId(clinicId);
    }
}
